<%--
  Created by IntelliJ IDEA.
  User: oldliu
  Date: 2021/3/22
  Time: 9:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script>
        alert(document.cookie);
    </script>
</head>
<body>
<%@include file="/checkLogin.jsp"%>
<%--<jsp:include page="checkLogin.jsp"/>--%>
<%
    //int name=34344;
    int count=1;
    Cookie[] cookies = request.getCookies();
    Cookie myCookie = null;
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("count")) {
                myCookie = cookie;
                break;
            }
        }
    }
    if (myCookie != null) {
        count=Integer.parseInt(myCookie.getValue())+1;
    }

        Cookie cookie = new Cookie("count", ""+count);
        //cookie.setHttpOnly(true);
        if(count>14){
            cookie.setMaxAge(0);//删除
        }else
        {
            cookie.setMaxAge(86400*7);  //7 days
        }

        response.addCookie(cookie);
        out.print("<h1>这是第"+count+"次访问</h1>");

%>
</body>
</html>
